package cn.maxmc.murderaddons.listener

import cn.maxmc.murderaddons.MurderAddons
import cn.maxmc.murderaddons.task.ArenaTaskManager
import io.izzel.taboolib.module.inject.TListener
import io.izzel.taboolib.module.locale.logger.TLoggerManager
import org.bukkit.Bukkit
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.scheduler.BukkitTask
import plugily.projects.murdermystery.api.events.game.MMGameStartEvent
import plugily.projects.murdermystery.api.events.game.MMGameStopEvent

@TListener(depend = ["MurderMystery"])
class HookListener: Listener {

    @EventHandler
    fun onStart(e: MMGameStartEvent) {
        val task = ArenaTaskManager.tasksCache[e.arena]?: return

        Bukkit.getScheduler().scheduleSyncDelayedTask(MurderAddons.plugin,{
            task.generateTask()
            val mur = e.arena.murdererList
            TLoggerManager.getLogger(MurderAddons.plugin).info("MurderList: $mur")
        },20L)
    }

    @EventHandler
    fun onEnd(e: MMGameStopEvent) {
        val task = ArenaTaskManager.tasksCache[e.arena] ?: return

        task.reset()
    }
}